<!--  -->
<template>
  <div class="app-container">
    <el-form :inline="true" size="small">
      <el-form-item label="直播间编号">
        <el-input
          v-model="mId"
          placeholder="请输入直播间编号"
          size="small"
        ></el-input>
      </el-form-item>
      <el-form-item label="直播间名称">
        <el-input
          v-model="mName"
          placeholder="请输入直播间名称"
          size="small"
        ></el-input>
      </el-form-item>

      <el-button icon="el-icon-search" type="primary" size="small" @click
        >搜索</el-button
      >
      <el-button icon="el-icon-refresh" size="small" @click>重置</el-button>
      <el-button icon="el-icon-edit" type="warning" size="small" @click="add"
        >新增</el-button
      >
      <el-button icon="el-icon-delete" type="danger" size="small" @click
        >删除</el-button
      >
      <el-button
        class="ref-btn"
        icon="el-icon-refresh"
        circle
        @click
      ></el-button>
    </el-form>
    <el-table :data="tableData" border stripe>
      <el-table-column
        type="selection"
        width="60"
        align="center"
      ></el-table-column>

      <template v-for="(i, index) in columns">
        <el-table-column
          v-if="index == 3"
          :key="i.id"
          :label="i.label"
          align="center"
          :width="i.width"
        >
          <template slot-scope="scope">
            <el-switch
              v-model="scope.row.toHome"
              :active-value="1"
              :inactive-value="2"
            ></el-switch>
          </template>
        </el-table-column>
        <el-table-column
          v-else-if="index == 4"
          :key="i.id"
          :label="i.label"
          align="center"
          :width="i.width"
        >
          <template slot-scope="scope">
            <el-switch
              v-model="scope.row.isAdv"
              :active-value="1"
              :inactive-value="2"
            ></el-switch>
          </template>
        </el-table-column>

        <el-table-column
          v-else
          :prop="i.data"
          :key="i.id"
          :label="i.label"
          align="center"
          :width="i.width"
        />
      </template>
      <el-table-column align="center" label="操作" width="200">
        <template slot-scope="scope">
          <el-button type="text" icon="el-icon-edit" @click="edit(scope.row)"
            >编辑</el-button
          >
          <el-button
            type="text"
            icon="el-icon-delete"
            style="color: #f66"
            @click="del(scope.$index, scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <div class="page">
      <el-pagination
        @size-change="sizeChange"
        @current-change="currentChange"
        :current-page.sync="page"
        :page-sizes="[20, 40, 80, 100]"
        :page-size="limit"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        background
      ></el-pagination>
    </div>

    <!-- 对话框 -->
    <el-dialog
      :title="dialogTitle"
      :visible.sync="showDialog"
      width="50%"
      @close="showDialog = false"
    >
      <el-form v-model="form" label-width="120px" :inline="false" size="normal">
        <el-form-item label="直播间编号">
          <el-input v-model="form.id" style="width: 220px"></el-input>
        </el-form-item>
        <el-form-item label="直播间名称">
          <el-input v-model="form.name" style="width: 220px"></el-input>
        </el-form-item>
        <el-form-item label="直播专家">
          <el-input v-model="form.expert" style="width: 220px"></el-input>
        </el-form-item>
        <el-form-item label="直播间封面">
          <el-input v-model="form.cover" style="width: 220px"></el-input>
        </el-form-item>
        <el-form-item label="是否置顶至首页">
          <el-switch
            v-model="form.toHome"
            :active-value="1"
            :inactive-value="0"
            style="width: 220px"
          />
        </el-form-item>
        <el-form-item label="所属专栏">
          <el-input v-model="form.column" style="width: 220px"></el-input>
        </el-form-item>
        <el-form-item label="是否开启预告">
          <el-switch
            v-model="form.isAdv"
            :active-value="1"
            :inactive-value="0"
            style="width: 220px"
          />
        </el-form-item>
        <el-form-item label="预告时间">
          <el-input v-model="form.advTime" style="width: 220px"></el-input>
        </el-form-item>
        <el-form-item label="开播时间">
          <el-input v-model="form.time" style="width: 220px"></el-input>
        </el-form-item>
        <el-form-item label="第三方接口">
          <el-input v-model="form.api" style="width: 220px"></el-input>
        </el-form-item>
      </el-form>

      <span slot="footer">
        <el-button @click="showDialog = false">取消</el-button>
        <el-button type="primary" @click="submit">确定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { getArticle } from "@/api/article";
export default {
  name: "slider",
  data() {
    return {
      mId: "",
      mName: "",
      keyword: "",
      submitType: "add",
      page: 1,
      limit: 10,
      total: 10,
      dialogTitle: "创建",
      showDialog: false,
      form: {},
      tableData: [
        {
          id: "1",
          name: "直播间1",
          cover: "封面图",
          toHome: 1,
          isAdv: 1,
          column: "专栏1",
          expert: "专家1",
          advTime: "2020-2-12 12:00:00",
          time: "2020-2-12 13:00:00",
          api: "http://aa.bb.cc",
        },
        {
          id: "2",
          name: "直播间2",
          cover: "封面图",
          toHome: 1,
          isAdv: 1,
          column: "专栏2",
          expert: "专家2",
          advTime: "2020-2-12 12:00:00",
          time: "2020-2-12 13:00:00",
          api: "http://aa.bb.cc",
        },
        {
          id: "3",
          name: "直播间3",
          cover: "封面图",
          toHome: 1,
          isAdv: 1,
          column: "专栏3",
          expert: "专家3",
          advTime: "2020-2-12 12:00:00",
          time: "2020-2-12 13:00:00",
          api: "http://aa.bb.cc",
        },
      ],

      columns: [
        { key: 0, label: `直播间编号`, data: "id", width: "90" },
        { key: 1, label: `直播间名称`, data: "name", width: "180" },
        { key: 2, label: `直播间封面`, data: "cover" },
        { key: 3, label: `是否推荐至首页`, data: "toHome", width: "120" },
        { key: 4, label: `是否发布预告`, data: "isAdv", width: "120" },
        { key: 5, label: `预告时间`, data: "advTime" },
        { key: 6, label: `开播时间`, data: "time" },
        { key: 7, label: `第三方接口`, data: "api" },
      ],
    };
  },
  created() {
    // getArticle();
  },
  methods: {
    add() {
      this.submitType = "add";
      this.showDialog = true;
    },
    edit(i) {
      this.form = i;
      this.showDialog = true;
    },
    submit() {
      var t = this.submitType;
      if (t == "add") {
        this.tableData.push(this.form);
        this.showDialog = false;
        this.form = {};
        this.$message.success("添加成功");
      } else if (t == "edit") {
      }
    },
    del(i, d) {
      this.$confirm('确认删除所选数据？', "确认删除", {
        confirmButtonText: "确认",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.tableData.splice(i, 1);
        })
        .catch(() => {});
    },
    sizeChange() {},
    currentChange() {},
  },
};
</script>
<style scoped>
.slideImg {
  width: 140px;
}
</style>
